package com.bms.client.controller;

import com.bms.client.pojo.FeiYongGuanLiChanXun;
import com.bms.client.pojo.FeiYongGuanLiZhengJia;
import com.bms.client.service.impl.FeiYongGuanLiServiceImpl;
import com.bms.client.utils.RedisUtils;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.HashMap;
import java.util.Map;

/**
 * 费用管理(FeiYongGuanLi)表控制层
 *
 * @author makejava
 * @since 2021-03-16 11:25:12
 * @version 1.0
 */
@RestController
@RequestMapping("feiYongGuanLi")
@Api(value = "费用管理(FeiYongGuanLi)管理",tags = "费用管理(FeiYongGuanLi)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class FeiYongGuanLiController {
    /**
     * 服务对象
     */
    @Resource
    private FeiYongGuanLiServiceImpl feiYongGuanLiServiceImpl;
    @Resource
    private RedisUtils redisUtils;

    /**
     * 通过主键查询单条数据
     *
     * chanXunFenYei
     * @return 单条数据
     */
    @RequestMapping(value = "chaXunFenYe", method = RequestMethod.POST)
    @ApiOperation(value = "列表查询分页接口", notes = "列表查询分页接口", httpMethod = "POST")
    public Map<String, Object> chaXunFenYe(@RequestBody @ApiParam(name = "chanXunFenYei", value = "pojo模型", required = true) FeiYongGuanLiChanXun feiYongGuanLiChanXun) {
        Map<String,String> conditionalQueue=new HashMap<>();
        conditionalQueue.put("keYanRenYuanXingMing","*"+feiYongGuanLiChanXun.getKeYanRenYuanXingMing()+"*");
        conditionalQueue.put("zhuangTai",feiYongGuanLiChanXun.getZhuangTai());
        conditionalQueue.put("boKuanZhuangTai",feiYongGuanLiChanXun.getBoKuanZhuangTai());
        conditionalQueue.put("xangWei",feiYongGuanLiChanXun.getXangWei());
        conditionalQueue.put("gaunLianId", String.valueOf(feiYongGuanLiChanXun.getGaunLianId()));
        return redisUtils.redisPage(feiYongGuanLiChanXun.getPage(),"feiYongGuanLi",conditionalQueue);
    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param feiYongGuanLiZhengJia 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "xinZengXiangMuJingFei", method = RequestMethod.POST)
    @ApiOperation(value = "新增项目经费", notes = "新增项目经费的接口", httpMethod = "POST")
    public Map<String, Object> xinZengXiangMuJingFei(@Valid @RequestBody @ApiParam(name = "feiYongGuanLiZhengJia", value = "pojo模型", required = true) FeiYongGuanLiZhengJia feiYongGuanLiZhengJia) {
        return this.feiYongGuanLiServiceImpl.xinZengXiangMuJingFei(feiYongGuanLiZhengJia);
    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param feiYongGuanLiZhengJia 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "xinZengHeZuoJingFei", method = RequestMethod.POST)
    @ApiOperation(value = "新增合作经费", notes = "新增合作经费", httpMethod = "POST")
    public Map<String, Object> xinZengHeZuoJingFei(@Valid @RequestBody @ApiParam(name = "feiYongGuanLiZhengJia", value = "pojo模型", required = true) FeiYongGuanLiZhengJia feiYongGuanLiZhengJia) {
        return this.feiYongGuanLiServiceImpl.xinZengHeZuoJingFei(feiYongGuanLiZhengJia);

    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "xinZengChuLaiJingFei", method = RequestMethod.POST)
    @ApiOperation(value = "新增出访来访经费", notes = "新增出访来访经费", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "zhuangTai",value = "状态（出访或来访）",paramType = "query",dataType = "String",required = true)
    })
    public Map<String, Object> xinZengChuLaiJingFei( @RequestParam(value = "zhuangTai") String zhuangTai, @RequestBody @ApiParam(name = "feiYongGuanLiZhengJia", value = "pojo模型", required = true) @Valid FeiYongGuanLiZhengJia feiYongGuanLiZhengJia) {
        return this.feiYongGuanLiServiceImpl.xinZengChuLaiJingFei(zhuangTai,feiYongGuanLiZhengJia);
    }

    /**
     * 通过主键更新单条数据
     *
     * @param id 主键
     * @param zhuangTai 审核状态
     * @param guanLiYuanPiZhu 管理员批注
     * @return 单条数据
     */
    @RequestMapping(value = "gengXinShenHeById", method = RequestMethod.POST)
    @ApiOperation(value = "更新审核状态的接口", notes = "更新审核的状态的接口", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "zhuangTai",value = "审核状态",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "guanLiYuanPiZhu",value = "管理员批注",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> gengXinShenHeById(@RequestParam(value = "id")  int id,
                                                 @RequestParam(value = "zhuangTai") String zhuangTai,
                                                 @RequestParam(value = "guanLiYuanPiZhu",required = false)  String guanLiYuanPiZhu) {
        return this.feiYongGuanLiServiceImpl.gengXinShenHeById(id,zhuangTai,guanLiYuanPiZhu);
    }

    /**
     * 通过主键更新单条数据
     *
     * @param id 主键
     * @param boKuanZhuangTai 审核状态
     * @param guanLiYuanPiZhu 管理员批注
     * @return 单条数据
     */
    @RequestMapping(value = "gengXinBoKuanById", method = RequestMethod.POST)
    @ApiOperation(value = "更新拨款状态的接口", notes = "更新拨款状态的接口", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "boKuanZhuangTai",value = "拨款状态",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "guanLiYuanPiZhu",value = "管理员批注",paramType = "query",dataType = "String",required = true)
    })
    public Map<String, Object> gengXinBoKuanById(@RequestParam(value = "id") int id,
                                                 @RequestParam(value = "boKuanZhuangTai") @Pattern(regexp = "已拨款|未拨款|拨款中",message = "已拨款 或 未拨款 或 拨款中") @Size(min = 0, max = 3, message = "状态在0-3个字符")String boKuanZhuangTai,
                                                 @RequestParam(value = "guanLiYuanPiZhu",required = false) @Size(min = 0, max = 25, message = "管理员批注必须在0~25位之间") String guanLiYuanPiZhu) {
        return this.feiYongGuanLiServiceImpl.gengXinBoKuanById(id,boKuanZhuangTai,guanLiYuanPiZhu);
    }
    @RequestMapping(value = "shanChu", method = RequestMethod.POST)
    @ApiOperation(value = "删除", notes = "删除", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "int",required = true)
    })
    public Map<String, Object> shanChu( @RequestParam(value = "id") int id) {
        return this.feiYongGuanLiServiceImpl.shanChuById(id);
    }
}